package com.graduate.nixingpotterty.common;

import lombok.Data;

/**
 * @author :ZhengHao
 * @version :1.0
 * @since :2025-01-05  22:16
 */

@Data
public class R<T> {
    private Integer code;
    private String message;
    private T data;

    // 成功时使用
    public static <T> R<T> ok(T data) {
        R<T> r = new R<>();
        r.setCode(200);
        r.setMessage("success");
        r.setData(data);
        return r;
    }

    public static <T> R<T> ok() {
        return ok(null);
    }

    // 失败时使用
    public static <T> R<T> fail(String message) {
        R<T> r = new R<>();
        r.setCode(500);
        r.setMessage(message);
        return r;
    }

    public static <T> R<T> fail(Integer code, String message) {
        R<T> r = new R<>();
        r.setCode(code);
        r.setMessage(message);
        return r;
    }

    // 构造函数
    public R() {}

    public R(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
}
